\documentclass[a4paper,11pt]{report}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc} % police encodee en UTF-8 %
\usepackage[english]{babel} % police fr %
\usepackage{graphicx} % pour inclusion d'images %
\usepackage{pgf} % pour dessiner %
\usepackage{tikz} % pour dessiner %
\usepackage{xcolor} % definition des couleurs %	
\usepackage[plainpages=false,pdfpagelabels,bookmarksnumbered,breaklinks=true]{hyperref} % pour les references %
\usepackage{amsmath} % pour les formules de maths %
\usepackage{latexsym} % pour les symboles maths %
\usepackage{amssymb} % pour les symboles maths %
\usepackage{aeguill} % pour les guillemets et accents francais %
\usepackage{listings} % pour les listings de code %
\usepackage{helvet} % police helvetica %
\usepackage{xspace}
\usepackage{../tikz-uml} % pour les diagrammes de classe

\newif\iffinal % definit un switch entre brouillon et version final
\finaltrue % a utiliser pour compiler le document en version finale

\iffinal
  \newcommand{\inputTikZ}[1]{%
    \input{fig/#1.tikz}%
  }%
  \hypersetup{%
    pdftitle={TikZ-UML},%
    pdfauthor={N. Kielbasiewicz},%
    pdfpagemode=UseOutlines,%
    linkbordercolor=0 0 0,%
    linkcolor=black,%
    citecolor=black,%
    colorlinks=true%
  }%
\else
  %\usepackage{showlabels}%
  \newcommand{\inputTikZ}[1]{%
    \includegraphics{fig/#1.pdf}%
  }%
  \hypersetup{%
    pdftitle={TikZ-UML},%
    pdfauthor={N. Kielbasiewicz},%
    pdfpagemode=UseOutlines,%
    linkbordercolor=0 0 0,%
    linkcolor=red,%
    citecolor=blue,%
    colorlinks=true%
  }%
\fi

% modification des dimensions de la page et de son centrage %
%\pagestyle{empty} % page brute %
\textwidth 17.5cm
\textheight 24.5cm
\hoffset=-2.4cm % position du point en haut {\`a} gauche %
\voffset=-1.9cm % position du point en haut {\`a} gauche %
%\itemsep -0.15cm % pour les listes %
%\parindent=1cm % pour les paragraphes %

% pour la justification a gauche et a droite et l'occupation maximale de l'espace dispo %
\sloppy
\hyphenpenalty 10000000

%\pagestyle{fancy} % on va mettre en tete et pied de page %
% \cfoot{\thepage}

%\fancypagestyle{plain}{%
%  \fancyhf{}
%  \fancyfoot{}
%  \renewcommand\headrulewidth{0pt}
%  \renewcommand\footrulewidth{0pt}
%}

%\fancyhead[RE,LO]{\leftmark}
%\fancyhead[RO,LE]{\thepage}
%\fancyfoot{}

\def\figureautorefname{figure}%
\def\tableautorefname{tableau}%
\def\partautorefname{partie}%
\def\chapterautorefname{chapitre}%
\def\appendixautorefname{annexe}%
\def\sectionautorefname{section}%
\def\subsectionautorefname{sous-section}%
\def\subsubsectionautorefname{paragraphe}%

\newcommand{\clearemptydoublepage}{\newpage{\pagestyle{empty}\cleardoublepage}}
\newcommand{\remarque}[1]{\begin{tikzpicture} \draw (0,0) node[regular polygon, regular polygon sides=3, draw, thick] {} node {\bf !};\end{tikzpicture} #1}

% redefinitions necessaires si inclusion du package marvosym
%\renewcommand{\Rightarrow}{\reflectbox{$\Leftarrow$}}
%\renewcommand{\Longrightarrow}{\reflectbox{$\Longleftarrow$}}

\newcommand{\tuml}{{\sc TikZ-UML} \xspace}
\newcommand{\TikZ}{{\sc TikZ} \xspace}

\lstset{language=[LaTeX]tex, basicstyle=\small, breaklines=true}

%\date{} % date %
\title{The \tuml package} % titre %
\author{Nicolas {\sc Kielbasiewicz}} % auteur %

\begin{document}

\maketitle

\tableofcontents

\chapter*{Preamble}
\addcontentsline{toc}{chapter}{Preamble}

In front of the wide range of possibilities given by the {\sc PGF/TikZ} library, and in front of the apparent lack of dedicated packages to UML diagrams, I was to develop the \tuml package, with a set of specialized commands and environments for these diagrams. 
It is dedicated to succeed pst-uml package, that was developped for similar reasons in {\sc PSTricks}. Actually, the package contains definitions of complete class diagrams, use case diagrams, sequence diagrams and state diagrams in a quite easy way. Some improvements are needed, but it is near the final release. 

Here is an example of class diagram you can draw :

\begin{center}
\inputTikZ{classdiagex}
\end{center}

We will now show you the various functionnalities of \tuml, but before we will talk about packages dependencies and installation of \tuml.

\section*{Dependencies}
\addcontentsline{toc}{section}{Dependencies}

\subsection*{Required packages}
\addcontentsline{toc}{subsection}{Required packages}

\begin{description}
\item[tikz :] It is useless to present this extremely powerful and complete drawing package. Every diagram generated by \tuml is in fact generated by \TikZ. It also gives some packages and libraries used by \tuml, such as the backgrounds, arrows, shapes, fit, shadows, decorations.markings libraries and the {\bf pgfkeys} package that manages macros options.
\item[ifthen :] This package offers the management of conditional test, such as if \ldots then \ldots else \ldots
\item[xstring :] This package offers string substitutions. It is used for the management of names between programmation items (classes, states, packages, \ldots) and and the nodes representing them.
\item[calc :] This package offers easy access to calculations.
\item[pgfopts :] This package is an add-on of the {\bf pgfkeys} package for the management of packages and classes options.
\end{description}

\subsection*{Others dependencies}
\addcontentsline{toc}{subsection}{Other dependencies}

For still unknown reasons, \tuml works fine if you have already included the {\bf babel} package with the language of your choice.

\subsection*{Installation}
\addcontentsline{toc}{section}{Installation}

Coming soon

\chapter{Class diagrams}\label{c.class}

\section{Package, class, attributes and operations}\label{s.packageclass}

\subsection{To define a package}\label{ss.package}

You can define a package with the {\tt umlpackage} environment :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/package.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{package}
\end{center}
\end{minipage}

\medskip

Both options {\tt x} and {\tt y} allow to define the package position in the figure. 
The default value for both of them is 0.

\begin{itemize}
\item When a package contains classes and sub-packages, its dimensions automatically fit to its content.
\item You can define as many packages as you want in a figure.
\item For an empty package (that contains no class), you can use a shortcut command : {\tt umlemptypackage} that takes the same arguments and options as the {\tt umlpackage} environment
\end{itemize}

\subsection{To define a class}\label{ss.class}

You can define a class with the {\tt umlclass} command :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/class.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{class}
\end{center}
\end{minipage}

Both options {\tt x} and {\tt y} allow to define the class position in the figure. 2 cases : 
if the class is defined inside a package, the class position is relative to the package; 
on the contrary, the class position is relative to the figure. The default value for both options is 0. 
For an empty class (that contains no attributes and no operations), you can use a shortcut command 
{\tt umlemptyclass} that takes only the class name for argument and the same options as the command {\tt umlclass}.

\subsubsection{To define the width of a class}

The default width of a class is 10ex. You can use the {\tt tt width} option to specify an other value :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/classwidth.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{classwidth}
\end{center}
\end{minipage}

\subsubsection{To specify the type of a class}

There is different types of classes : class, interface, typedef, enum. You can specify it with the {\tt type} option (the default value is class) :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/classtype.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{classtype}
\end{center}
\end{minipage}

\medskip

The type is written between $\ll$ and $\gg$ above the class name, excepted the class type (default behavior), and the abstract type, where the class name is written in italic style instead :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/classabstract.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{classabstract}
\end{center}
\end{minipage}

Notice that aliases exists for each value of the type option : {\tt umlabstract}, {\tt umltypedef}, {\tt umlenum}, {\tt umlinterface}.

\subsubsection{To specify template parameters}

For a template class, you can use the {\tt template} option to specify the template parameters list :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/classtemplate.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{classtemplate}
\end{center}
\end{minipage}

\subsubsection{Name of the node defining a class}

Pour donner le nom d'une classe, il arrive que l'on utilise des caracteres speciaux, comme le \_{} ou les : quand on specifie le namespace. Le mecanisme interne de \tuml{} nomme le n\oe{}ud definissant une classe avec le meme nom. Or, l'utilisation du $\backslash$ et des : est interdite pour nommer un n\oe{}ud en \TikZ. Il est tout a fait possible que d'autres caracteres viennent poser probleme. Il faut donc proceder a une substitution de caractere, operation appelee des que l'on definit ou utilise le nom d'une classe. Nous avons vu dans les exemples precedents que cela fonctionne pour le \_{}.

\subsection{To define attributes and operations}\label{ss.attrop}

The attributes of a class are defined with the second argument of the {\tt umlclass} command. You write the attributes list using {\tt \\} as a delimiter. The operations of a class are defined with the third argument of the {\tt umlclass} command. 

To define a static attribute or a static operation, you can use the {\tt umlstatic} command. In a similar way, the {\tt umlvirt} command is used to define a virtual operation :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/attr-and-op.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{attr-and-op}
\end{center}
\end{minipage}

\section{To define a relation between classes}\label{s.rel}

\subsection{General macro}\label{ss.relgen}

Each class or package is draw as a node sharing the same name. To define a relation
between two classes, you just need to specify the source class name, the target class name and a set of options specific to the relation :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/relation.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{relation}
\end{center}
\end{minipage}

From a UML semantic point of view, there are 11 different relations. Every type of relation is defined in \tuml :

\begin{description}
\item[A dependency :] You can use the {\tt umldep} command
\item[An association :] You can use the {\tt umlassoc} command
\item[A unidirectional association :] You can use the {\tt umluniassoc} command
\item[An aggregation :] You can use the {\tt umlaggreg} command
\item[A unidirectional aggregation ] You can use the {\tt umluniaggreg} command
\item[A composition :] You can use the {\tt umlcompo} command
\item[A unidirectional composition :] You can use the {\tt umlunicompo} command
\item[An import :] You can use the {\tt umlimport} command
\item[An inheritance :] You can use the {\tt umlinherit} command
\item[An implementation :] You can use the {\tt umlimpl} command
\item[A realisation :] You can use the {\tt umlreal} command
\end{description}

These 11 shortcuts are based on the same scheme (the {\tt umlrelation} command) and take theoretically the same set of options. Nevertheless, some options concern only part of them.

\subsection{To define the geometry of a relation}\label{ss.relgeom}

As you may have seen in previous examples, you can specify the geometric shape of a relation
with the \hypertarget{geometry}{{\tt geometry}} option. It needs a value among the following list : - - (straight line), -| (horizontal then vertical), |- (vertical then horizontal), -|- (horizontal chicane) ou |-| (vertical chicane). These values are very inspired from \TikZ philosophy.

It seems that this option is used very often. That is why a shortcut of the {\tt umlrelation} command has been defined each possible value of the {\tt geometry} option :

\begin{description}
\item[umlHVrelation :] shortcut of {\tt umlrelation} with geometry=-|
\item[umlVHrelation :] shortcut of {\tt umlrelation} with geometry=|-
\item[umlHVHrelation :] shortcut of {\tt umlrelation} with geometry=-|-
\item[umlVHVrelation :] shortcut of {\tt umlrelation} with geometry=|-|
\end{description}

\remarque{For each of these 4 shortcuts, the {\tt geometry} option is forbidden.}

\remarque{There is no shortcut for the value - - : this is the default value for the {\tt umlrelation} command.}

\subsection{To adjust the geometry of a relation}\label{ss.relfitgeom}

When the geometry is built with 2 segments, you can define the coordinates of the auto-built point, named control node. 
Then, instead of using {\tt umlrelation}, you should use the {\tt umlCNrelation} command, or one of its 11 shortcuts :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/relationCN.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{relationCN}
\end{center}
\end{minipage}

\medskip

When the geometry is built with 3 segments, the relative position of the middle segment between classes is defined by the midlle of the classes nodes. You can adjust this parameter with the \hypertarget{weight}{{\tt weight}} option :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/relationweight.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{relationweight}
\end{center}
\end{minipage}

In some cases, this option is not very convenient, because it needs to compute the option value to give.
There is another possibility by uusing the  \hypertarget{arm1}{{\tt arm1}} and  \hypertarget{arm2}{{\tt arm2}} options, that control the size 
of the first and last segment respectively. Let's see the 2 following examples using respectively the {\tt weight} option and the {\tt arm1} option :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/relationweight2.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{relationweight2}
\end{center}
\end{minipage}

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/relationarm.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{relationarm}
\end{center}
\end{minipage}

\medskip

The {\tt arm1} and {\tt arm2} options also take negative values. How does it work then ? 
A positive value means an arm oriented to the right direction (to the right or to the top), whereas a negative valuemeans an arm oriented to the opposite direction, that allows you to draw other 3-segments relations :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/relationarm2.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{relationarm2}
\end{center}
\end{minipage}


\subsection{To define informations about attributes of a relation}\label{ss.relattr}

A relation means a dependency between two classes and represents an attribute in most of the cases. You can define its name with the {\tt arg1} option or the {\tt arg2} option, and its multiplicity with the {\tt mult1} option or the {\tt mult2} option :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/relationarg.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{relationarg}
\end{center}
\end{minipage}

\medskip

For unidirectional relations, you should use only {\tt arg2} and {\tt mult2} options. That is why shortcuts have been defined, namely the {\tt arg} option and the {\tt mult} option respectively.

In addition, when you define the name and the multiplicity of an attribute, you may prefer use the all-in-one following options {\tt attr1}, {\tt attr2} and {\tt attr} :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/relationattr.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{relationattr}
\end{center}
\end{minipage}

\medskip

This has an advantage : the semantic of the two values has disappeared and you can switch them for convenience :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/relationattr2.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{relationattr2}
\end{center}
\end{minipage}

\medskip

\subsection{To place information about attributes of a relation}\label{ss.relposattr}

You can place information seen in previous section with the following options : {\tt pos1}, {\tt pos2} and {\tt pos}.
The {\tt umlrelation} command determine by itself if name and multiplicity should be written on left and right or on top and bottom of the arrow, according to the geometry and their placement. For those who know \TikZ enough, the mechanism is based on {\tt auto} and {\tt swap} options.

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/relationpos.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{relationpos}
\end{center}
\end{minipage}

\medskip

You may have noticed that the range of values of the position depends on the number of segments composing the arrow. For a straight line, position has to be between  0 (source class) and 1 (target class). If there are 2 segments, then position has to be between 0 et 2 (target class), the value 1 corresponding to the control node. Otherwise, position has to be between 0 et 3, values 1 and 2 corresponding to the first and second control node respectively.

\subsection{To adjust the alignment of information about attributes of a relation}\label{ss.relalign}

Name and multiplicity of an attribute, when they are written on top and bottom of the relation, are centered by default. You can define an other alignment.
The options {\tt align1}, {\tt align2} and {\tt align} are used to have ragged right or ragged left text :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/relationalign.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{relationalign}
\end{center}
\end{minipage}

\subsection{To define and place the stereotype of a relation}\label{ss.relstereo}

The stereotype of a relation is a keyword contained between $\ll$ and $\gg$. 
You can define it with the option {\tt stereo} and place it with the option \hypertarget{posstereo}{{\tt pos stereo}}.

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/relationstereo.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{relationstereo}
\end{center}
\end{minipage}

\subsection{To modify the anchor points of a relation}\label{ss.relanchor}

The default behavior of a relation is to start from the center anchor of the source class node and to end to the center anchor of the target class node.
You can adjust this with the options \hypertarget{anchor1}{{\tt anchor1}} and \hypertarget{anchor2}{{\tt anchor2}}.

\medskip

\begin{minipage}{0.6\textwidth}
\lstinputlisting{fig/relationanchor.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{relationanchor}
\end{center}
\end{minipage}

\medskip

You give angular values in degree and they can be negative. The internal mechanism of \TikZ uses modulos. The value 0 is east, 90 is north, 180 (or -180) is west, et 270 (or -90) is south. The following figure illustrates this option and its angular meaning on 2 examples of rectangular nodes, (class nodes for instance). You can notice that border anchors (to use \TikZ vocabulary) depend on node dimensions.

\begin{center}
\inputTikZ{tikzanchor}
\end{center}

You will very often define {\tt anchor1} and {\tt anchor2} simultaneously. In this case, you can use the all-in-one option \hypertarget{anchors}{{\tt anchors}} :

\medskip

\begin{minipage}{0.6\textwidth}
\lstinputlisting{fig/relationanchors.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{relationanchors}
\end{center}
\end{minipage}

\subsection{To define a recursive relation}\label{ss.relrec}

You can define recursive relations, namely a relation from a class to itself. Then, the 
{\tt geometry} option is disabled, but 3 specific options are available : {\tt angle1} determines
the start angle, {\tt angle2} determines the end angle, and {\tt loopsize} controls the size of the loop.

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/relationrec.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{relationrec}
\end{center}
\end{minipage}

\medskip

When you use recursive relations, you will notice that you will need the 3 options simultaneously. This is the reason why a compact form is defined, the {\tt recursive} option, and the following syntax :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/relationrec2.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{relationrec2}
\end{center}
\end{minipage}

\subsection{Name of auto-built points of a relation}\label{ss.relptname}

In order to understand the purpose of giving a name to a relation, one should explain how arrows are defined.

To build an arrow, we need to define control nodes, and a name for each one. The only way to identify a relation is to give a name using a id counter. This counter is incremented each time we define a relation in a picture.
Let's suppose the relation has the id $i$. The name of the relation, called relname in the following, is : relation-$i$

The first defined node is the middle of the class nodes. It is called {\it relname-middle}. To simplify, we will not deal with the placement of the argument and its multiplicity here. So, there are 3 cases :

\begin{enumerate}
\item If the arrow is a straight line or a recursive line, it is renamed in {\it relname-1}.

\begin{center}
\inputTikZ{relationptname}
\end{center}

\item If the arrow has one right angle, the node placed at the angle is named {\it relname-2}, that is enough to draw the arrow. 2 other nodes are defined, placed at the middle of each arc and named respectively {\it relname-1} and {\it relname-3}.

\begin{center}
\inputTikZ{relationHVptname}
\end{center}

\item If the arrow has 2 right angles, they are defined with
{\it relname-middle}, that is enough to draw the arrow. Nodes placed at the angles are named respectively {\it relname-2} and {\it relname-4}. 3 other nodes are defined, at the middle of each arc, 
named respectively {\it relname-1}, {\it relname-3}, and {\it relname-5}.

\begin{center}
\inputTikZ{relationHVHptname}
\end{center}
\end{enumerate}

This default behavior is not easy to use, because the value of the counter is not defined by the user, and depends on the order of definition of the relations in the picture. This is the reason why you can define {\it relname} thanks to the {\tt name} option. In the two following sections, you will see when this option is useful.

\subsection{To draw an intersection point between relations}\label{ss.relpt}

When you draw a diagram, it occurs that relations cross other ones or share arcs. Let's take two crossing arrows.
Can both start points go graphically to both end points ? If yes, you will want to draw a point at the intersection of the arrows, and this point should be a control node of one the the relations. To define the point, you can use the {\tt umlpoint} command.

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/point.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{point}
\end{center}
\end{minipage}

\section{Comments / constraints note}\label{s.note}

A note is a text comment attached to a class or a relation. The {\tt umlnote} command needs the name of the node as argument :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/noteclass.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{noteclass}
\end{center}
\end{minipage}

\medskip

Here again, you can give the name of a control node of a relation to attach the note. Giving a name to the relation will be very useful :

\medskip

\begin{minipage}{0.6\textwidth}
\lstinputlisting{fig/noterelation.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{noterelation}
\end{center}
\end{minipage}

\medskip

\medskip

Notes have 2 uses : comments and contraints (generally in OCL format).

\medskip

The {\tt umlnote} command has the following options :

\begin{description}
\item[x, y] These 2 options define the coordinates of the note.
\item[width] This option defines the width of the note. For \TikZ users, it encapsulates the {\tt text width} option
\item[weight, arm, anchor1, anchor2, anchors] These options has the same behavior as for {\tt umlrelation}, {\tt arm} being equivalent to {\tt arm1}, namely attached to the note.
\end{description}

\medskip

\begin{minipage}{0.6\textwidth}
\lstinputlisting{fig/noteVHV.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{noteVHV}
\end{center}
\end{minipage}

\medskip

\medskip

For a note, you can also use the {\tt geometry} option, as for {\tt umlrelation}. Then, aliases have been defined : {\tt umlHVnote}, {\tt umlVHnote}, {\tt umlHVHnote} and {\tt umlVHVnote}.

\remarque{For each of these aliases, the {\tt geometry} option is forbidden.}

\remarque{There is no alias for the - - value. It is the default one.}

\section{To change preferences}\label{s.classset}

Thanks to the {\tt tikzumlset} command, you can change default preferences for packages, classes and notes. The available options are :

\begin{description}
\item[text : ] allows you to set text color for every drawn object (=black by default),
\item[draw :] allows you to define edge color for every drawn object (=black by default),
\item[fill class :] allows you to define the background color of a class node (=yellow!20 by default),
\item[fill template :] allows you to define the background color of a template node (=yellow!2 by default),
\item[fill package :] allows you to define the background color of a package (=blue!20 by default),
\item[fill note :] allows you to define the background color for a note (=green!20 by default),
\item[font :] allows you to define the font style for every drawn object (=$\backslash$small by default).
\end{description}

Furthermore, relation commands has the {\tt style} option taking a \TikZ style name as value.

Let's see the definition of the {\tt umlinherit} command :

\begin{lstlisting}
\tikzstyle{tikzuml inherit style}=[color=\tikzumldrawcolor, -open triangle 45]
\newcommand{\umlinherit}[3][]{\umlrelation[style={tikzuml inherit style}, #1]{#2}{#3}}
\end{lstlisting}

You can easily define a command on this model by defining a particular style.

\section{Examples}

\subsection{Example from introduction, step by step}

We will now build step by step the picture seen in introduction to understand the behavior of each used command.

\subsubsection{Definition of packages p, sp1 and sp2}

The package p is placed at (0,0) (default), and the sub-packages sp1 and sp2 respectively at (0,0) and (10,-6).

{\color{red!70!black}
\lstinputlisting[firstline=1, lastline=2]{fig/classdiagex.tikz}\vspace{-0.4cm}
\lstinputlisting[firstline=10, lastline=11]{fig/classdiagex.tikz}\vspace{-0.4cm}
\lstinputlisting[firstline=15, lastline=15]{fig/classdiagex.tikz}\vspace{-0.4cm}
\lstinputlisting[firstline=19, lastline=19]{fig/classdiagex.tikz}
}

\begin{center}
\inputTikZ{classdiagstep1}
\end{center}

\subsubsection{Definition of classes A, B, C, D and their attributes and operations}

The class A is placed at (0,0) in the sub-package sp1 and has a template parameter : T. The class B is placed 3 units below A, still in the sub-package sp1. The interface C is placed at (0,0) in the sub sp2. 
The class D is placed at (2,-11) in the package p.

Class A has two attributes. Class B has one attribute and two operations (one is virtual). Class C has two attributes. Classe D has one attribute.

\lstinputlisting[firstline=1, lastline=2]{fig/classdiagex.tikz}\vspace{-0.4cm}
{\color{red!70!black}
\lstinputlisting[firstline=3, lastline=9]{fig/classdiagex.tikz}\vspace{-0.4cm}
}
\lstinputlisting[firstline=10, lastline=11]{fig/classdiagex.tikz}\vspace{-0.4cm}
{\color{red!70!black}
\lstinputlisting[firstline=12, lastline=14]{fig/classdiagex.tikz}\vspace{-0.4cm}
}
\lstinputlisting[firstline=15, lastline=15]{fig/classdiagex.tikz}\vspace{-0.4cm}
{\color{red!70!black}
\lstinputlisting[firstline=16, lastline=18]{fig/classdiagex.tikz}\vspace{-0.4cm}
}
\lstinputlisting[firstline=19, lastline=19]{fig/classdiagex.tikz}

\begin{center}
\inputTikZ{classdiagstep2}
\end{center}


\subsubsection{Definition of relations}

We define an association between classes C and B, a unidirectional composition between classes D and C, an import relation named "import" between sub-packages sp2 and sp1 (with modification of anchors), a recursive aggregation on class D and an inheritnce between classes D and B. On thses relations, we will specify argument names and multiplicities. You can notice the value given to place 
these elements on each arrow according to the geometry.

\medskip

\hspace{-0.7cm}\lstinline{...}
{\color{red!70!black}
\lstinputlisting[firstline=20, lastline=24]{fig/classdiagex.tikz}
}

\begin{center}
\inputTikZ{classdiagstep3}
\end{center}

\subsubsection{Definition of notes}

We add a note attached to class B and a note attached to the import relation.

\medskip

\hspace{-0.7cm}\lstinline{...}
{\color{red!70!black}
\lstinputlisting[firstline=25]{fig/classdiagex.tikz}
}

\begin{center}
\inputTikZ{classdiagstep4}
\end{center}

\subsubsection{Setting style}

We illustrate the use of the {\tt tikzumlset} command by changing colors associated to class and font. 
We can also change colors of a given class with {\tt draw}, {\tt text} and {\tt fill} options.

\medskip

\begin{lstlisting}
\tikzumlset{fill class=red!20, fill template=violet!10, font=\bfseries\footnotesize}
\begin{tikzpicture}
...
\umlclass[x=2,y=-11, fill=orange!50, draw=white, text=red]{D}{
  n : uint
  }{}
...
\end{tikzpicture}
\end{lstlisting}

\begin{center}
\inputTikZ{tikzumlset}
\end{center}

\subsection{To define a specialization of a class}

A specialization of a classe is an inheritance from a templace class in which one of the template parameters is defined. To draw this relation,  you will use the {\tt umlreal} command , and its {\tt stereo} option :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/specialisation.tikz}
\end{minipage}
\begin{minipage}{0.5\textwidth}
\begin{center}
\inputTikZ{specialisation}
\end{center}
\end{minipage}

\section{Priority rules of options and known bugs}\label{s.classbug}

\begin{enumerate}
\item The {\tt geometry} option has always the priority on the others options. It means for instance that if it has a non-default value, then {\tt angle1}, {\tt angle2} and {\tt loopsize} options, defining recursive relations, will be ignored.
\item As far as a template class is concerned, there are cases in which a relation about it will not be drawn correctly, as in the picture below, where the aggregation symbol is hidden by the template parameter :

\begin{minipage}{0.6\textwidth}
\lstinputlisting{fig/bugtemplate.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{bugtemplate}
\end{center}
\end{minipage}

\medskip

To solve this problem,  you van link the arrow between the template part of class A and class B, by adding the suffix -template and adjusting the start anchor (the -30 value is correct here) :

\medskip

\begin{minipage}{0.6\textwidth}
\lstinputlisting{fig/bugtemplate2.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{bugtemplate2}
\end{center}
\end{minipage}

\medskip

\item If you define a class with a name having the : character in it -- typically when you give the namespace of the class -- it may have a conflict with the french (or frenchb or francais) option of the babel package. Indeed, these options add a white-space before the : character if the writer forgot it, that is a problem for the access operator ::. If we take the example of class definition, we should obtain :

\medskip

\begin{minipage}{0.6\textwidth}
\lstinputlisting{fig/class.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\begin{tikzpicture}
\umlclass[x=0,y=0]{namespace : :class\_name}{}{}
\end{tikzpicture}
\end{center}
\end{minipage}

\medskip

The solution is to use a specific macro given by these options of babel package you have to use in the preamble of your document :

\medskip

\begin{lstlisting}
\frenchbsetup{AutoSpacePunctuation=false}
\end{lstlisting}

\medskip

\item The automatic placement of argument names and multiplicity on a relation can be surprising when you can to deactivate it. Let's take the example shown in introduction. If we focus on the association relation and its attributes {\it toto} and {\it tata}, {\it toto} is above, {\it tata} is below. 
If we justify to the right the {\it tata} attribute (and change its position to 0.1), positions of {\it tata} and its multiplicity exchange.

\begin{center}
\inputTikZ{bugalign}
\end{center}

\end{enumerate}

\chapter{Use case diagrams}\label{c.usecase}

Here is an example of use case diagram you can draw :

\begin{center}
\inputTikZ{usecaseex}
\end{center}

We will see how to define the four constitutive elements of such a diagram : the system, the actors, the use cases and the relations.

\section{To define a system}\label{s.system}

A system is defined by the {\tt umlsystem} environment :

\medskip

\begin{minipage}{0.6\textwidth}
\lstinputlisting{fig/system.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{system}
\end{center}
\end{minipage}

\medskip

Both options {\tt x} and {\tt y} allow to place the system in the picture. The default value is 0. Inside this environment, you will define use cases, whereas outside, you will define actors.

\section{To define an actor}\label{s.actor}

You can define an actor with the {\tt umlactor} command :

\medskip

\begin{minipage}{0.6\textwidth}
\lstinputlisting{fig/actor.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{actor}
\end{center}
\end{minipage}

\medskip

Both options {\tt x} and {\tt y} allow to place the actor in the picture. The default value is 0. You can change dimensions of the actor symbol with the {\tt scal} option. It also adapts position of the label below :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/actorscale.tikz}
\end{minipage}
\begin{minipage}{0.5\textwidth}
\begin{center}
\inputTikZ{actorscale}
\end{center}
\end{minipage}

\medskip

The actor symbol size is defined according to the font size (ex unit), whereas the distance between the symbol and the label is in cm. You can adjust it if you need with the {\tt below} option (0.5cm by default).

\medskip
 
\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/actorfont.tikz}
\end{minipage}
\begin{minipage}{0.5\textwidth}
\begin{center}
\inputTikZ{actorfont}
\end{center}
\end{minipage}

\section{To define a use case}\label{s.usecase}

You can define a use case with the {\tt umlusecase} command :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/usecase.tikz}
\end{minipage}
\begin{minipage}{0.5\textwidth}
\begin{center}
\inputTikZ{usecase}
\end{center}
\end{minipage}

\medskip

Both options {\tt x} and {\tt y} allow to place the use case in the picture or in the container system. The default value is 0. The text argument is the label of the use case. The node representing the use case has a default name, based on a global counter, that is like usecase-17. For pratical reasons, you can rename it thanks to the {\tt name} option.

Furthermore, you can set the witdh of the use case with the {\tt width} option.

\medskip

Now, we can talk about relations between use cases, systems and actors.

\section{To define a relation}\label{s.userel}

Relations in a user case diagram are of 4 categories :

\begin{itemize}
\item Inheritance relations, between actors or between use cases. You can use the {\tt umlinherit} command and its aliases, ie \autoref{ss.relgen}.
\item Association relations, between an actor and a use cases. You can use the {\tt umlassoc} command and its aliases, ie \autoref{ss.relgen}.
\item Include and extend relations. Graphically, it is a dependency relation, as for class diagrams, with the stereotype {\tt extend} or {\tt include}. You can use aliases of the {\tt umlrelation} command, named 
{\tt umlinclude}, {\tt umlHVinclude}, \ldots, {\tt umlextend}, {\tt umlHVextend}, \ldots, to define such relations.
\end{itemize}

\hyperlink{anchor1}{{\tt anchor1}}, \hyperlink{anchor2}{{\tt anchor2}}, \hyperlink{anchors}{{\tt anchors}}, \hyperlink{arm1}{{\tt arm1}}, \hyperlink{arm2}{{\tt arm2}}, \hyperlink{weight}{{\tt weight}}, \hyperlink{geometry}{{\tt geometry}} (only for {\tt umlinclude} and {\tt umlextend}), and \hyperlink{posstereo}{{\tt pos stereo}} options are available here.

\medskip

\begin{minipage}{0.51\textwidth}
\lstinputlisting{fig/include-and-extend.tikz}
\end{minipage}
\begin{minipage}{0.49\textwidth}
\begin{center}
\inputTikZ{include-and-extend}
\end{center}
\end{minipage}

\medskip

\section{To change preferences}\label{s.fitusecase}

With the {\tt tikzumlset} command, you can change default colors for use cases, systems, actors and relations :

\begin{description}
\item[text :] allows to set the text color (=black by default),
\item[draw :] allows to set the edge colors (=black by default),
\item[fill usecase :] allows to set the background color for use cases (=blue!20 by default),
\item[fill system :] allows to set the background color for systems (=white by default),
\item[font :] allows to set the font style (=$\backslash$small by default).
\end{description}

You can also use {\tt text}, {\tt draw} and {\tt fill} options on a particular element to change its colors, as shown in the introduction example.

\section{Examples}

\subsection{Example from introduction, step by step}

\subsubsection{Definition of actors}

{\color{red!70!black}
\lstinputlisting[firstline=11, lastline=13]{fig/usecaseex.tikz}
}

\begin{center}
\inputTikZ{usecasediagstep1}
\end{center}

\subsubsection{Definition of use cases}

We also show here the use of the {\tt fil} option.

{\color{red!70!black}
\lstinputlisting[firstline=3, lastline=8]{fig/usecaseex.tikz}\vspace{-0.4cm}
}
\lstinputlisting[firstline=11, lastline=13]{fig/usecaseex.tikz}

\begin{center}
\inputTikZ{usecasediagstep2}
\end{center}

\subsubsection{Definition of the system}

As the system is a box used as a new coordinate system, we have to change coordinates of use cases.

{\color{red!70!black}
\lstinputlisting[firstline=2, lastline=2]{fig/usecaseex.tikz}\vspace{-0.4cm}
}
\lstinputlisting[firstline=3, lastline=8]{fig/usecaseex.tikz}\vspace{-0.4cm}
{\color{red!70!black}
\lstinputlisting[firstline=9, lastline=9]{fig/usecaseex.tikz}\vspace{-0.4cm}
}
\lstinputlisting[firstline=10, lastline=13]{fig/usecaseex.tikz}

\begin{center}
\inputTikZ{usecasediagstep3}
\end{center}

\subsubsection{Definition of relations and of the note}

You will notice here the use of the {\tt name} option to ensure the definition of the note, and its interest for use cases, in order to ignore the order of their definition, as shown in the following example :

\lstinputlisting[firstline=2, lastline=13]{fig/usecaseex.tikz}\vspace{-0.4cm}
{\color{red!70!black}
\lstinputlisting[firstline=14, lastline=25]{fig/usecaseex.tikz}
}

\begin{center}
\inputTikZ{usecasediagstep4}
\end{center}

\chapter{State-transitions diagrams}\label{c.statetrans}

Here is an example of state-transition diagram you can draw :

\begin{center}
\inputTikZ{statediagex}
\end{center}

Now, we will see how to define parts of these diagrams, namely the ten sorts of state and the transitions.

\newpage

\section{To define a state}\label{s.state}

A "standard" state can be defined with the {\tt umlstate} environment :

\medskip

\begin{minipage}{0.51\textwidth}
\lstinputlisting{fig/state.tikz}
\end{minipage}
\begin{minipage}{0.49\textwidth}
\begin{center}
\inputTikZ{state}
\end{center}
\end{minipage}

\medskip

Both options {\tt x} and {\tt y} allows to place the state in the figure, or in another state. 
The default value is 0. The argument to give is the label of the state. The node representing the state has a default name, based on a global counter. 
For practical reasons, when you define a transition for instance, you can rename it with the {\tt name} option.

\medskip

You can also define the maximal width of a state with the  {\tt width} (10ex by default).

\medskip

You can define a state in another state. Then, the coordinates of the sub-states are relative to the parent state :

\medskip

\begin{minipage}{0.51\textwidth}
\lstinputlisting{fig/stateinner.tikz}
\end{minipage}
\begin{minipage}{0.49\textwidth}
\begin{center}
\inputTikZ{stateinner}
\end{center}
\end{minipage}

\medskip

If you want to define a state without detailing it, you can use the {\tt umlbasicstate} command, that is an alias of the {\tt umlstate} environment.

\medskip

Let's talk about the specific states :

\medskip

\begin{minipage}{0.51\textwidth}
\lstinputlisting{fig/statespecial.tikz}
\end{minipage}
\begin{minipage}{0.49\textwidth}
\begin{center}
\inputTikZ{statespecial}
\end{center}
\end{minipage}

\medskip

From left to right and top to bottom :

\medskip

\begin{itemize}
\item An initial state is defined with the {\tt umlstateinitial} command.
\item A final state is defined with the {\tt umlstatefinal} command.
\item A join state is defined with the {\tt umlstatejoin} command.
\item A decision state is defined with the {\tt umlstatedecision} command.
\item An enter state is defined with the {\tt umlstateenter} command.
\item An exit state is defined with the {\tt umlstateexit} command.
\item An end state is defined with the {\tt umlstateend} command.
\item An history state is defined with the {\tt umlstatehistory} command.
\item A deep history state is defined with the {\tt umlstatedeephistory} command.
\end{itemize}

\medskip

These commands take several options : {\tt name}, to rename the node, and {\tt width} to set their size. You can use these commands in a {\tt umlstate} environment :

\medskip

\begin{minipage}{0.51\textwidth}
\lstinputlisting{fig/statename.tikz}
\end{minipage}
\begin{minipage}{0.49\textwidth}
\begin{center}
\inputTikZ{statename}
\end{center}
\end{minipage}

\medskip

\section{To define a transition}\label{s.trans}

Transitions are relations between states in a state-transition diagram. You can define them with the {\tt umltrans} command, that is an alias of the {\tt umlrelation} command. There are unidirectional transitions and recursive transitions.

\subsection{To define a unidirectional transition}\label{s.unitrans}

Thanks to the {\tt geometry} option, usual aliases are available : {\tt umlHVtrans}, {\tt umlVHtrans}, {\tt umlVHVtrans} and {\tt umlHVHtrans}. Graphically, the use of these aliases are the most interesting, because corners are rounded.

\medskip

\begin{minipage}{0.51\textwidth}
\lstinputlisting{fig/transition.tikz}
\end{minipage}
\begin{minipage}{0.49\textwidth}
\begin{center}
\inputTikZ{transition}
\end{center}
\end{minipage}

\medskip

Every option of the {\tt umlrelation} command can be used with the {\tt umltrans} command and its aliases.

\subsection{To define a recursive transition}\label{s.rectrans}

Recursive transitions are graphically the most difficult to manage, because their shape is a rounded rectangle, contrary to recursive relations in a class diagram. Conceptually, it is as if the {\tt geometry} option has the value -|- or |-|, that is to say arrows composed of several segments.

\medskip

\begin{minipage}{0.51\textwidth}
\lstinputlisting{fig/transitionrec.tikz}
\end{minipage}
\begin{minipage}{0.49\textwidth}
\begin{center}
\inputTikZ{transitionrec}
\end{center}
\end{minipage}

\medskip

The {\tt recursive direction} option is fundamental. Indeed, giving values of start angle and end angle is not enough to determine the start direction and the end direction of the recursive arrow, because it does not define the normal direction. Then, we have to precise it. There are 2 cases :

\medskip

\begin{itemize}
\item The arrow can be composed of 3 segments. In this case, usable nodes are shown as follows :

\begin{center}
\inputTikZ{transitionrec-rtr-ptname}
\end{center}

\item The arrow can be composed of 4 segments. In this case, usable nodes are shown as follows :

\medskip

\begin{center}
\inputTikZ{transitionrec-rtb-ptname}
\end{center}

\vspace{-4cm}

\end{itemize}

\subsection{To define a transition between sub states}\label{ss.substatetrans}

When you want to define transitions between sub-states, transitions are drawn inside the parent state.Then, you have to define them inside the {\tt umlstate} environment. Let's compare the two following examples :

\medskip

\begin{minipage}{0.51\textwidth}
\lstinputlisting{fig/transitioninnerbug.tikz}
\end{minipage}
\begin{minipage}{0.49\textwidth}
\begin{center}
\inputTikZ{transitioninnerbug}
\end{center}
\end{minipage}

\begin{minipage}{0.51\textwidth}
\lstinputlisting{fig/transitioninner.tikz}
\end{minipage}
\begin{minipage}{0.49\textwidth}
\begin{center}
\inputTikZ{transitioninner}
\end{center}
\end{minipage}

\section{To change preferences}\label{s.fitstatetrans}

With the {\tt tikzumlset} command, you can change default colors for states and transitions :

\begin{description}
\item[text :] allows to set text color (=black by default),
\item[draw :] allows to set the edge color and the color of initial, final and join states (=black by default),
\item[fill state :] allows to set the background color of a state (=yellow!20 by default),
\item[font :] allows to set the font style (=$\backslash$small by default).
\end{description}

You can also use the {\tt text}, {\tt draw} and {\tt fill} options on a particular element, in order to change its colors, as shown in the introduction example.

\section{Examples}

\subsection{Example from introduction, step by step}

\subsubsection{Definition of basic states}

\medskip

\begin{center}
\inputTikZ{statediagstep1}
\end{center}

\newpage

{\color{red!70!black}
\lstinputlisting[firstline=2, lastline=3]{fig/statediagex.tikz}\vspace{-0.37cm}
\lstinputlisting[firstline=5, lastline=5]{fig/statediagex.tikz}\vspace{-0.37cm}
\lstinputlisting[firstline=11, lastline=11]{fig/statediagex.tikz}\vspace{-0.37cm}
\lstinputlisting[firstline=16, lastline=16]{fig/statediagex.tikz}\vspace{-0.37cm}
\lstinputlisting[firstline=21, lastline=21]{fig/statediagex.tikz}\vspace{-0.37cm}
\lstinputlisting[firstline=25, lastline=25]{fig/statediagex.tikz}
}

\vspace{-0.5cm}

\subsubsection{Definition of specific states}

\medskip

\begin{center}
\inputTikZ{statediagstep2}
\end{center}

\medskip

\lstinputlisting[firstline=2, lastline=3]{fig/statediagex.tikz}\vspace{-0.4cm}
{\color{red!70!black}
\lstinputlisting[firstline=4, lastline=4]{fig/statediagex.tikz}\vspace{-0.4cm}
}
\lstinputlisting[firstline=5, lastline=5]{fig/statediagex.tikz}\vspace{-0.37cm}
\lstinputlisting[firstline=11, lastline=11]{fig/statediagex.tikz}\vspace{-0.4cm}
{\color{red!70!black}
\lstinputlisting[firstline=14, lastline=14]{fig/statediagex.tikz}\vspace{-0.4cm}
}
\lstinputlisting[firstline=16, lastline=16]{fig/statediagex.tikz}\vspace{-0.4cm}
{\color{red!70!black}
\lstinputlisting[firstline=17, lastline=17]{fig/statediagex.tikz}\vspace{-0.37cm}
\lstinputlisting[firstline=19, lastline=19]{fig/statediagex.tikz}\vspace{-0.4cm}
}
\lstinputlisting[firstline=21, lastline=21]{fig/statediagex.tikz}\vspace{-0.37cm}
\lstinputlisting[firstline=25, lastline=25]{fig/statediagex.tikz}

\subsubsection{Definition of transitions}

\lstinputlisting[firstline=2, lastline=5]{fig/statediagex.tikz}\vspace{-0.4cm}
{\color{red!70!black}
\lstinputlisting[firstline=6, lastline=10]{fig/statediagex.tikz}\vspace{-0.4cm}
}
\lstinputlisting[firstline=11, lastline=11]{fig/statediagex.tikz}\vspace{-0.4cm}
{\color{red!70!black}
\lstinputlisting[firstline=12, lastline=13]{fig/statediagex.tikz}\vspace{-0.4cm}
}
\lstinputlisting[firstline=14, lastline=14]{fig/statediagex.tikz}\vspace{-0.4cm}
{\color{red!70!black}
\lstinputlisting[firstline=15, lastline=15]{fig/statediagex.tikz}\vspace{-0.4cm}
}
\lstinputlisting[firstline=16, lastline=17]{fig/statediagex.tikz}\vspace{-0.4cm}
{\color{red!70!black}
\lstinputlisting[firstline=18, lastline=18]{fig/statediagex.tikz}\vspace{-0.4cm}
}
\lstinputlisting[firstline=19, lastline=19]{fig/statediagex.tikz}\vspace{-0.4cm}
{\color{red!70!black}
\lstinputlisting[firstline=20, lastline=20]{fig/statediagex.tikz}\vspace{-0.4cm}
}
\lstinputlisting[firstline=21, lastline=21]{fig/statediagex.tikz}\vspace{-0.4cm}
{\color{red!70!black}
\lstinputlisting[firstline=22, lastline=24]{fig/statediagex.tikz}\vspace{-0.4cm}
}
\lstinputlisting[firstline=25, lastline=25]{fig/statediagex.tikz}

\begin{center}
\inputTikZ{statediagstep3}
\end{center}

%\section{Regles de priorite des options et bugs identifies}\label{s.statetransbug}
%
\chapter{Sequence diagrams}\label{c.seq}

Here is an example of sequence diagram you can draw :

\begin{center}
\inputTikZ{seqdiagex}
\end{center}

Now, we will talk about elements that compose such diagrams.

\section{To define a sequence diagram}\label{s.seqdiag}

Here is the main difference from previous diagrams : to define a sequence diagram, you have to use a {\tt umlseqdiag} environment.
Its aim is to initialise some global variables and to draw the lifelines of each object in the diagram. You have to understand that commands and environments you will use to define a sequence diagrams place the elements (calls, objects, \ldots ) automatically. We will talk about that in more details later.

\section{To define an object}\label{s.objs}

\subsection{Types of objects}\label{ss.obj}

You can define an object with the {\tt umlobject} command :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/object.tikz}
\end{minipage}
\begin{minipage}{0.5\textwidth}
\begin{center}
\inputTikZ{object}
\end{center}
\end{minipage}

\medskip

The default type is a class instance. You can give the class name with the {\tt class} option (empty by default).

\medskip

The {\tt stereo} option allows to set the type of object. It needs one of the following values : object (default value), actor, entity, boundary, control, database, multi. The last six are drawn in the following picture, from left to right and top to bottom :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/objectstereo.tikz}
\end{minipage}
\begin{minipage}{0.5\textwidth}
\begin{center}
\inputTikZ{objectstereo}
\end{center}
\end{minipage}

\subsection{Automatic placement of an object}\label{ss.objpos}

Both options {\tt x} and {\tt y} allows to place an object. You only have to use them if the automatic placement does not do what you need. Its behavior is the following :

\begin{itemize}
\item The default value of the {\tt y} option is 0, that means the default placement of an object is at the top of the sequence diagram.
\item The default value of the {\tt x} option is the product of 4 by the value of the global counter identifying the object : for instance, for the second object defined in a diagram, the {\tt x} option is set to 8 by default, \ldots
\end{itemize}

Unless the width of the object is too large, a shift of 4 is enough. If not, you use the {\tt x} option.

\subsection{To scale an object}\label{ss.objdim}

The {\tt scale} option of the {\tt umlobject} command allows to scale an object, its symbol and its font size :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/objectscale.tikz}
\end{minipage}
\begin{minipage}{0.5\textwidth}
\begin{center}
\inputTikZ{objectscale}
\end{center}
\end{minipage}

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/objectfont.tikz}
\end{minipage}
\begin{minipage}{0.5\textwidth}
\begin{center}
\inputTikZ{objectfont}
\end{center}
\end{minipage}

\section{To define a function call}\label{s.calls}

Function calls are the core of sequence diagrams. Then, we need a motor either smart enough to propose a satisfacting default behavior, either easy enough to parametrize.

From a technical point of view, and I open here a parenthesis, there are two ways to implement function calls :

\begin{enumerate}
\item Either we use the nodal matrix structure of \TikZ. The advantage is to work on a pre computed nodal grid and then to place elements of a sequence diagram easily (and fast for compilation) with exactly one counter.
\item Either we use an automatical positioning of nodes with a set of coordinates, here the time instant, that allows total freedom for the user and make its work easier.
\end{enumerate}

I chose the second way, to keep the philosophy used to implement the other diagrams in this package. Indeed, if the lack of a grid needs a more accurate computation core, and as a result more compilation time, you can define most of the elements very easily, such as constructor calls, drawn according to the standard. That is different from others UML softwares I used before. I close the parenthesis.

\subsection{Basic / recursive calls}\label{ss.call}

You can define a function call with the {\tt umlcall} environment. Of course, you can define {\tt umlcall} environments in other ones :

\medskip

\begin{minipage}{0.4\textwidth}
\lstinputlisting{fig/call.tikz}
\end{minipage}
\begin{minipage}{0.6\textwidth}
\begin{center}
\inputTikZ{call}
\end{center}
\end{minipage}

\medskip

You have to give the name of the source object and the name of the destination object. If you give the same name as source and destination, you define a recursive call. In this case, you may prefer use an alias, the {\tt umlcallself} environment :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/callself.tikz}
\end{minipage}
\begin{minipage}{0.5\textwidth}
\begin{center}
\inputTikZ{callself}
\end{center}
\end{minipage}

\subsection{To place a call}\label{ss.calldt}

The {\tt dt} option allows to place a function call on a lifeline, relatively to the last call drawn on this lifeline. It has no default value. Its unit is ex. The default behavior is to shift the call you define to avoid overwriting between to consecutive calls :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/calldt.tikz}
\end{minipage}
\begin{minipage}{0.5\textwidth}
\begin{center}
\inputTikZ{calldt}
\end{center}
\end{minipage}

\medskip

You can also set spaces for recursive calls with the {\tt padding} option. It set the space just below the recursive call :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/callpadding.tikz}
\end{minipage}
\begin{minipage}{0.5\textwidth}
\begin{center}
\inputTikZ{callpadding}
\end{center}
\end{minipage}

\subsection{Synchron / asynchron calls}\label{ss.callsync}

The {\tt type} option allows to tell if the call is synchron (default value) or asynchron :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/callsync.tikz}
\end{minipage}
\begin{minipage}{0.5\textwidth}
\begin{center}
\inputTikZ{callsync}
\end{center}
\end{minipage}

\subsection{Operation, arguments and return value}\label{ss.callop}

You can give the function name in a call and its arguments with the {\tt op} option :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/callop.tikz}
\end{minipage}
\begin{minipage}{0.5\textwidth}
\begin{center}
\inputTikZ{callop}
\end{center}
\end{minipage}

\medskip

\remarque{Beware of the braces, so as to the comma between i and k is deactivated as an option delimiter. WIthout them, there will be a compilation error.}

\medskip

You can also set the return value with the {\tt return} option, with the same warning :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/callreturn.tikz}
\end{minipage}
\begin{minipage}{0.5\textwidth}
\begin{center}
\inputTikZ{callreturn}
\end{center}
\end{minipage}

\medskip

\subsection{To define a constructor call}\label{ss.create}

Constructor calls are special function calls, insofar as they build a new object. They are not messages between two lifelines, but between a lifeline and an object.

To define a constructor call, you can use the {\tt umlcreatecall} command :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/createcall.tikz}
\end{minipage}
\begin{minipage}{0.5\textwidth}
\begin{center}
\inputTikZ{createcall}
\end{center}
\end{minipage}

\medskip

You can notice that everything behave normally after a constructor call.

\medskip

As an object builder, the {\tt umlcreatecall} command has {\tt class}, {\tt stereo} and {\tt x} options.

As a function call, it has the {\tt dt} option.

\subsection{To name a call}\label{ss.callname}

The {\tt name} option allows to give a name for a function call. It is not useful actually, insofar as this option was added for the definition of combined fragments, but as you will see, combined fragment does not use this feature. Maybe this option will be used for future developments of the package.

\section{To define a combined fragment}\label{s.fragments}

Combined fragments are the second family of elements in a sequence diagram, with the function calls. You can define them with the {\tt umlfragment} environment :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/fragment.tikz}
\end{minipage}
\begin{minipage}{0.5\textwidth}
\begin{center}
\inputTikZ{fragment}
\end{center}
\end{minipage}

\subsection{Informations of a fragment}\label{ss.fraginfos}

The {\tt type} option allows to set the keyword on the top left corner : opt, alt, loop, par, assert, \ldots The default value is opt.

The {\tt label} option allows to set information such as the condition for a opt fragment :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/fragmentlabel.tikz}
\end{minipage}
\begin{minipage}{0.5\textwidth}
\begin{center}
\inputTikZ{fragmentlabel}
\end{center}
\end{minipage}

\medskip

The {\tt inner xsep} option allows to shift type and label to the left. The default value is 1 and its unit is ex.

\subsection{Name of a fragment}\label{ss.fragname}

You can give a name to a combined fragment with the {\tt name} option. It can be useful when you want to attach a note on a fragment :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/fragmentname.tikz}
\end{minipage}
\begin{minipage}{0.5\textwidth}
\begin{center}
\inputTikZ{fragmentname}
\end{center}
\end{minipage}

\subsection{To define regions of a fragment}\label{ss.fragpart}

Let's take a alt fragment. It represents a switch-case instruction block. To represent each case, you need to set regions in the fragment. For this purpose, you can use the {\tt umlfpart} command :

\medskip

\begin{minipage}{0.5\textwidth}
\lstinputlisting{fig/fragmentpart.tikz}
\end{minipage}
\begin{minipage}{0.5\textwidth}
\begin{center}
\inputTikZ{fragmentpart}
\end{center}
\end{minipage}

\section{To change preferences}\label{s.fitseq}

Thanks to the {\tt tikzumlset} command, you can set colors for calls, fragments and objects :

\begin{description}
\item[text :] allows to set the text color (=black by default),
\item[draw :] allows to set the color od edges and arrows (=black by default),
\item[fill object :] allows to set the background color of objects (=yellow !20 by default),
\item[fill call :] allows to set the background color for calls (=white by default),
\item[fill fragment :] allows to set the background color for fragments (=white by default),
\item[font :] allows to set the font style (=$\backslash$small by default).
\end{description}

You can also use the options {\tt text}, {\tt draw} and {\tt fill} on a particular element, as in the example of introduction.

There is an exception : {\tt umlcreatecall}. The options {\tt text}, {\tt draw} and {\tt fill} set the colors of the call, whereas options {\tt text obj}, {\tt draw obj} and {\tt fill obj} set the colors of the object.

\medskip

\begin{minipage}{0.6\textwidth}
\lstinputlisting{fig/createcallset.tikz}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\begin{center}
\inputTikZ{createcallset}
\end{center}
\end{minipage}

\section{Examples}

\subsection{Example from introduction, step by step}

\subsubsection{Definition of objects}

{\color{red!70!black}
\lstinputlisting[firstline=2,lastline=6]{fig/seqdiagex.tikz}\vspace{-0.4cm}
\lstinputlisting[firstline=36,lastline=36]{fig/seqdiagex.tikz}
}

\begin{center}
\inputTikZ{seqdiagstep1}
\end{center}

\subsubsection{Definition of the call opa and its components}

\lstinputlisting[firstline=2,lastline=6]{fig/seqdiagex.tikz}\vspace{-0.4cm}
{\color{red!70!black}
\lstinputlisting[firstline=7, lastline=7]{fig/seqdiagex.tikz}\vspace{-0.4cm}
\lstinputlisting[firstline=9, lastline=9]{fig/seqdiagex.tikz}\vspace{-0.4cm}
\lstinputlisting[firstline=11, lastline=12]{fig/seqdiagex.tikz}\vspace{-0.4cm}
\lstinputlisting[firstline=14, lastline=15]{fig/seqdiagex.tikz}\vspace{-0.4cm}
\lstinputlisting[firstline=17, lastline=17]{fig/seqdiagex.tikz}\vspace{-0.4cm}
\lstinputlisting[firstline=20, lastline=20]{fig/seqdiagex.tikz}\vspace{-0.4cm}
\lstinputlisting[firstline=22, lastline=23]{fig/seqdiagex.tikz}\vspace{-0.4cm}
\lstinputlisting[firstline=25, lastline=25]{fig/seqdiagex.tikz}\vspace{-0.4cm}
\lstinputlisting[firstline=27, lastline=27]{fig/seqdiagex.tikz}\vspace{-0.4cm}
}
\lstinputlisting[firstline=36,lastline=36]{fig/seqdiagex.tikz}

\begin{center}
\inputTikZ{seqdiagstep2}
\end{center}

\subsubsection{Definition of the calls following the construction of E}

\lstinputlisting[firstline=2,lastline=7]{fig/seqdiagex.tikz}\vspace{-0.4cm}
\lstinputlisting[firstline=9, lastline=9]{fig/seqdiagex.tikz}\vspace{-0.4cm}
\lstinputlisting[firstline=11, lastline=12]{fig/seqdiagex.tikz}\vspace{-0.4cm}
\lstinputlisting[firstline=14, lastline=15]{fig/seqdiagex.tikz}\vspace{-0.4cm}
\lstinputlisting[firstline=17, lastline=17]{fig/seqdiagex.tikz}\vspace{-0.4cm}
\lstinputlisting[firstline=20, lastline=20]{fig/seqdiagex.tikz}\vspace{-0.4cm}
\lstinputlisting[firstline=22, lastline=23]{fig/seqdiagex.tikz}\vspace{-0.4cm}
\lstinputlisting[firstline=25, lastline=25]{fig/seqdiagex.tikz}\vspace{-0.4cm}
\lstinputlisting[firstline=27, lastline=27]{fig/seqdiagex.tikz}\vspace{-0.4cm}
{\color{red!70!black}
\lstinputlisting[firstline=28, lastline=28]{fig/seqdiagex.tikz}\vspace{-0.4cm}
\lstinputlisting[firstline=30, lastline=34]{fig/seqdiagex.tikz}\vspace{-0.4cm}
}
\lstinputlisting[firstline=36,lastline=36]{fig/seqdiagex.tikz}

\begin{center}
\inputTikZ{seqdiagstep3}
\end{center}

\subsubsection{Definition of fragments}

\lstinputlisting[firstline=2,lastline=7]{fig/seqdiagex.tikz}\vspace{-0.4cm}
{\color{red!70!black}
\lstinputlisting[firstline=8, lastline=8]{fig/seqdiagex.tikz}\vspace{-0.4cm}
}
\lstinputlisting[firstline=9, lastline=9]{fig/seqdiagex.tikz}\vspace{-0.4cm}
{\color{red!70!black}
\lstinputlisting[firstline=10, lastline=10]{fig/seqdiagex.tikz}\vspace{-0.4cm}
}
\lstinputlisting[firstline=11, lastline=12]{fig/seqdiagex.tikz}\vspace{-0.4cm}
{\color{red!70!black}
\lstinputlisting[firstline=13, lastline=13]{fig/seqdiagex.tikz}\vspace{-0.4cm}
}
\lstinputlisting[firstline=14, lastline=15]{fig/seqdiagex.tikz}\vspace{-0.4cm}
{\color{red!70!black}
\lstinputlisting[firstline=16, lastline=16]{fig/seqdiagex.tikz}\vspace{-0.4cm}
}
\lstinputlisting[firstline=17, lastline=17]{fig/seqdiagex.tikz}\vspace{-0.4cm}
{\color{red!70!black}
\lstinputlisting[firstline=18, lastline=19]{fig/seqdiagex.tikz}\vspace{-0.4cm}
}
\lstinputlisting[firstline=20, lastline=20]{fig/seqdiagex.tikz}\vspace{-0.4cm}
{\color{red!70!black}
\lstinputlisting[firstline=21, lastline=21]{fig/seqdiagex.tikz}\vspace{-0.4cm}
}
\lstinputlisting[firstline=22, lastline=23]{fig/seqdiagex.tikz}\vspace{-0.4cm}
{\color{red!70!black}
\lstinputlisting[firstline=24, lastline=24]{fig/seqdiagex.tikz}\vspace{-0.4cm}
}
\lstinputlisting[firstline=25, lastline=25]{fig/seqdiagex.tikz}\vspace{-0.4cm}
{\color{red!70!black}
\lstinputlisting[firstline=26, lastline=26]{fig/seqdiagex.tikz}\vspace{-0.4cm}
}
\lstinputlisting[firstline=27, lastline=28]{fig/seqdiagex.tikz}\vspace{-0.4cm}
{\color{red!70!black}
\lstinputlisting[firstline=29, lastline=29]{fig/seqdiagex.tikz}\vspace{-0.4cm}
}
\lstinputlisting[firstline=30, lastline=34]{fig/seqdiagex.tikz}\vspace{-0.4cm}
{\color{red!70!black}
\lstinputlisting[firstline=35, lastline=35]{fig/seqdiagex.tikz}\vspace{-0.4cm}
}
\lstinputlisting[firstline=36,lastline=36]{fig/seqdiagex.tikz}

\begin{center}
\inputTikZ{seqdiagstep4}
\end{center}

\section{Known bugs and perspectives}\label{s.seqbug}

\begin{enumerate}
\item When you define a fragment on a set of calls just after a constructor call, the automatic shift does not work. You have to use the {\tt dt} with a value greather than 7 to the first call inside the fragment.
\item The automatic placement of objects with a multiple of 4 is not very convenient. A shift of 4 relatively to the last object drawn should be better.
\item You can not give arguments to constructor calls.
\item You can not force the drawing of the activity area of a "non working" object.

\begin{center}
\inputTikZ{bugcall}
\end{center}

\end{enumerate}
\end{document}